package io.geekidea.boot.otherstores.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import io.geekidea.boot.otherstores.dto.addOtherStore;
import io.geekidea.boot.otherstores.dto.updateOtherStore;
import io.geekidea.boot.otherstores.entity.OtherStores;
import io.geekidea.boot.otherstores.entity.Stores;
import io.geekidea.boot.otherstores.query.OtherQuery;
import io.geekidea.boot.otherstores.query.total;
import org.apache.ibatis.annotations.*;

import java.util.List;


@Mapper
public interface OtherStoresMapper extends BaseMapper<OtherStores> {

    List<OtherStores> findByList(OtherQuery otherQuery);

    @Update("update tb_other_stores set deleted = 1 where id = #{id}")
    int delByIdInt(int id);

    @Select("select id,name from tb_store where areaId = #{areaId}")
    List<Stores> getStoreList(Integer areaId);

    @Insert("insert into tb_other_stores(`name`,`code`,snNumber,availableInventory,areaId,storesId,createdBy) values (#{name},#{code},#{snNumber},#{availableInventory},#{areaId},#{storesId},#{createdBy} )  ")
    int addStore(addOtherStore addOtherStore);

    @Update(" update tb_other_stores  set `name` = #{name} ,`code`= #{code},snNumber = #{snNumber},availableInventory = #{availableInventory},areaId = #{areaId},updatedTime = #{updatedTime},updatedBy = #{updatedBy},storesId = #{storesId} where id= #{id}")
    int updateOtherStore(updateOtherStore updateOtherStore);

    total getTotal(OtherQuery otherQuery);

    @Select("select s.*,a.name areaName,t.name scoreName from tb_other_stores s\n" +
            "        left join tb_area a on a.id = s.areaId\n" +
            "        left join tb_store t on t.id  = s.storesId\n" +
            "        where s.deleted = 0 and s.id = #{id}")
    OtherStores getStore(Integer id);

}
